package com.luotat.employeeclient.controller;

import com.luotat.pojo.result.Result;
import com.luotat.employeeclient.client.EmployeeServiceImpl;
import com.luotat.pojo.employee.Employee;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping("/employee")
public class EmployeeServiceClientController
{
    private final EmployeeServiceImpl employeeService;

    /**
     * 添加员工
     */
    @PostMapping
    public Result insert(@RequestBody Employee employee)
    {
        log.info("In client insert");
        return employeeService.insert(employee);
    }

    /**
     * 删除员工
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id)
    {
        log.info("In client delete");
        return employeeService.delete(id);
    }

    // 修改员工
    @PutMapping
    public Result update(@RequestBody Employee employee)
    {
        log.info("In client update");
        return employeeService.update(employee);
    }

    /**
     * 根据id查询员工
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id)
    {
        log.info("In client getById");
        return employeeService.getById(id);
    }

    /**
     * 查询所有员工
     */
    @GetMapping("/getAll")
    public Result getAll()
    {
        log.info("In client getAll");
        return employeeService.getAll();
    }
}